package com.etime.yqtsponsor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.etime.yqtsponsor.dao.ActivePicBankMapper;
import com.etime.yqtsponsor.pojo.ActivePicBank;
import com.etime.yqtsponsor.pojo.ActiveTheme;
import com.etime.yqtsponsor.service.ActivePicBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ly
 * @date 2022/7/22 16:35
 */
@Service
public class ActivePicBankServiceImpl implements ActivePicBankService {

    @Autowired
    private ActivePicBankMapper activePicBankMapper;

    /**
     * 获取banner轮播图
     * @param activeTheme
     * @return
     */
    @Override
    public List<ActivePicBank> selectBannerPics(ActiveTheme activeTheme){
        QueryWrapper<ActivePicBank> wrapper = new QueryWrapper<>();
        if(activeTheme!=null){
            String bannerPicIds = activeTheme.getBannerPicIds();
            bannerPicIds = bannerPicIds.substring(2,bannerPicIds.length()-2);
            bannerPicIds = bannerPicIds.replaceAll("\"", "");
            String[] split = bannerPicIds.split(",");
//            List<Integer> list = Arrays.asList(split).stream().mapToInt(Integer::parseInt).boxed().collect(Collectors.toList());
//            List<String> list = Arrays.asList(split).stream().collect(Collectors.toList());
            List<String> list = Arrays.asList(split);
            System.out.println(bannerPicIds);
            wrapper.in("id",list);
        }
        return activePicBankMapper.selectList(wrapper);
    }
}
